<?PHP

class OP_SearchWidget extends OP_WidgetTemplate{
	function render(){
		$title = empty( $this->values['title'] ) ? __( 'Search' ) : apply_filters('widget_title', $this->values['title']);

		$searchform_template = get_template_directory() . '/searchform.php';

		// Use current theme search form if it exists
		if ( file_exists($searchform_template) ) {
			include_once($searchform_template);
		} else {
			echo '<form method="get" action="';
			bloginfo('url');
			echo '/"><div>';
			echo '<label class="hidden">',
				'</label>',
				'<input type="text" name="s" size="15" value="';
				
			echo get_search_query() == '' ? 'Search for...' : get_search_query();
			echo '" onfocus="this.value=\'\'" />',
				'<input class="submit" type="submit" value="',
				attribute_escape(__('Search')),
				'" />',
				'</div></form>';
		}
	
	}

	function do_post($post){
		$title = strip_tags(stripslashes($post["title"]));
		return compact( 'title' );		
	}				

	function options(){
		$title = attribute_escape($this->values['title']);
		
		echo '<p><label for="'.$this->widget->class.'-title-'.$this->values['number'].'">'._e('Title:').' <input class="widefat" id="'.$this->widget->class.'-title-'.$this->values['number'].'" name="'.$this->widget->class.'['.$this->values['number'].'][title]" type="text" value="'.$title.'" /></label></p>';
	}
}

$widget = new OP_Widget('op_search');
$widget->setMeta('OP Search',"A search form for your blog");
$widget->setDefaults(array('title'=>''));

$opw_search = new OP_SearchWidget($widget);
add_action('widgets_init', array($opw_search, 'init'));

?>